/**
 *格式化时间
 */
// exports.formatDate = time => {
//   const tmpDate = new Date(time)
//   const year = tmpDate.getFullYear()
//   const mathon = tmpDate.getMonth() + 1
//   const day = tmpDate.getDate()
//   const hours = tmpDate.getHours()
//   const minutes = tmpDate.getMinutes()
//   return year + '-' + mathon + '-' + day + ' ' + hours + ':' + minutes
// }

exports.formatDate = (time, fmt) => {
  const date = new Date(time)
  if (/(y+)/.test(fmt)) {
    fmt = fmt.replace(
      RegExp.$1,
      (date.getFullYear() + '').substr(4 - RegExp.$1.length)
    )
  }
  const o = {
    'M+': date.getMonth() + 1,
    'd+': date.getDate(),
    'h+': date.getHours(),
    'm+': date.getMinutes(),
    's+': date.getSeconds()
  }
  for (const k in o) {
    if (new RegExp(`(${k})`).test(fmt)) {
      const str = o[k] + ''
      fmt = fmt.replace(
        RegExp.$1,
        RegExp.$1.length === 1 ? str : padLeftZero(str)
      )
    }
  }
  return fmt
}

function padLeftZero(str) {
  return ('00' + str).substr(str.length)
}
/*
* 格式化金钱
*/
exports.formatMoney = value => {
  return Number(value).toFixed(2)
}
/*
* 隐藏用户手机号中间四位
*/
exports.hidePhone = phone => {
  return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2')
}
/*
* 隐藏用户手机号中间四位
*/
exports.splitImg = strings => {
  return strings.split(',')[0]
}
